"""
Code to assess success of matching and who is there and so forth.
"""


from psd.register.models import *


def gender_string( rr ):
    if rr.is_group:
        return "group"
    elif rr.is_man_only:
        return "man"
    elif rr.is_woman_only:
        return "woman"
    else:
        return "other"
#        return rr.indiv.vagueGenderDesc()

def gay_str_bi( rr ):
    if rr.wants_mf:
        return "bi"
    elif (rr.wants_m and rr.treat_as_man) or (rr.wants_f and rr.treat_as_woman):
        return "gay"
    else:
        return "str"


def date_distribution_iter( event_name ):
    
    folks = RegRecord.objects.filter( event=event_name )

    # header
    yield "PSDID,minicode,gender,desire,bi,num.M,num.W,num.G,num.O,num.Fr\n"
    for f in folks:
        countdict = { "M":0, "W":0, "G":0, "Friend":0, "O":0 }
        for dt in DateRecord.objects.filter(event=event_name,psdid=f.psdid ):
            dt_rr = fetch_regrecord( event_name, dt.other_psdid )
            if dt.friend_date:
                countdict["Friend"] += 1
            elif dt_rr.is_group:
                countdict["G"] += 1
            elif dt_rr.is_man_only:
                countdict["M"] += 1
            elif dt_rr.is_woman_only:
                countdict["W"] += 1
            else:
                countdict["O"] += 1
        outstr = ','.join( [f.psdid, f.miniCode(), gender_string(f), '/'.join(f.seek_genders), gay_str_bi(f), str(countdict["M"]), str(countdict["W"]), str(countdict["G"]), str(countdict["O"]), str(countdict["Friend"]) ] )
        yield outstr + "\n"




#def date_count_iter( event_name ):
#    """
#    Print out the number of matches each dater got
#    """
#    
#    folks = RegRecord.objects.filter( event=event_name )
#
#    # header
#    yield "PSDID,minicode,gender,desire,bi,date.PSDID,date.type,round,match,their.match\n"
#
#    for f in folks:
#        for dt in DateRecord.objects.filter(event=event_name,psdid=f.psdid ):
#            outstr = ','.join( [f.psdid, f.miniCode(), gender_string(f), '/'.join(f.seek_genders), gay_str_bi(f) )
#            
#            outstr += dt.friend_date + "," + dt.round + "," + dt. 
#            #dt_rr = fetch_regrecord( event_name, dt.other_psdid )
#            yield outstr + "\n"



                            
